package settings;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.GridView;

import com.imstlife.vending.R;
import com.imstlife.vending.adapter.ManageAdapter;
import com.imstlife.vending.utils.Cof;
import com.imstlife.vending.utils.SharePersistentUtil;
import com.imstlife.vending.utils.T;
import com.imstlife.vending.vo.DrinkListVo;

public class ManageFragment extends Fragment {



	private GridView gridView;

	private ManageAdapter manageAdapter;

	private Button btnOneKey;
	private DrinkListVo  drinkListVo;


	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootLayout = inflater.inflate(R.layout.fragment_manage, container,
				false);


		drinkListVo = ((DrinkListVo) getActivity().getIntent().getSerializableExtra("drinks"));
		initView(rootLayout);
		return rootLayout;
	}

	private void initView(View rootLayout) {

		gridView = (GridView) rootLayout.findViewById(R.id.grid_fg_manage_drinklist);
		if(drinkListVo!=null){


		manageAdapter = new ManageAdapter(drinkListVo.getDrinkList(),getActivity());
		gridView.setAdapter(manageAdapter);

		btnOneKey = (Button) rootLayout.findViewById(R.id.btn_fg_manage_one_key);
		btnOneKey.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				for (int i = 1; i <= 60; i++) {

					SharePersistentUtil.saveSharePersistent(getActivity(), Cof.APP_IMAGE_CACHE, i + "", 5);
				}
				manageAdapter.notifyDataSetChanged();
				T.showLong(getActivity(),"货道商品计数设置为5");
			}
		});
		}else{
			//未获取到商品列表
			T.showLong(getActivity(),"未获取到商品列表");
		}

	}

}
